package com.charger.topuphistory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.charger.PromoteOperations.domain.Client;
import com.charger.PromoteOperations.service.IClientService;
import com.charger.trade.domain.Chargingrecords;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charger.common.annotation.Log;
import com.charger.common.core.controller.BaseController;
import com.charger.common.core.domain.AjaxResult;
import com.charger.common.enums.BusinessType;
import com.charger.topuphistory.domain.Topuphistory;
import com.charger.topuphistory.service.ITopuphistoryService;
import com.charger.common.utils.poi.ExcelUtil;
import com.charger.common.core.page.TableDataInfo;

/**
 * 充值记录Controller
 * 
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/topuphistory/topuphistory")
public class TopuphistoryController extends BaseController
{
    @Autowired
    private ITopuphistoryService topuphistoryService;
    @Autowired
    private IClientService clientService;
    /**
     * 查询充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('topuphistory:topuphistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(Topuphistory topuphistory)
    {
        startPage();
        List<Topuphistory> list = topuphistoryService.selectTopuphistoryList(topuphistory);


        for (Topuphistory aa:list){
            System.out.println(aa.getClientId());
            Client client = clientService.selectClientById(aa.getClientId());
            aa.setClient(client);
        }
        return getDataTable(list);
    }

    /**
     * 导出充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('topuphistory:topuphistory:export')")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Topuphistory topuphistory)
    {
        List<Topuphistory> list = topuphistoryService.selectTopuphistoryList(topuphistory);
        ExcelUtil<Topuphistory> util = new ExcelUtil<Topuphistory>(Topuphistory.class);
        util.exportExcel(response, list, "充值记录数据");
    }

    /**
     * 获取充值记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('topuphistory:topuphistory:query')")
    @GetMapping(value = "/{topuphistoryId}")
    public AjaxResult getInfo(@PathVariable("topuphistoryId") Long topuphistoryId)
    {
        return success(topuphistoryService.selectTopuphistoryByTopuphistoryId(topuphistoryId));
    }

    /**
     * 新增充值记录
     */
    @PreAuthorize("@ss.hasPermi('topuphistory:topuphistory:add')")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Topuphistory topuphistory) {

        return toAjax(topuphistoryService.insertTopuphistory(topuphistory));
    }

    /**
     * 修改充值记录
     */
    @PreAuthorize("@ss.hasPermi('topuphistory:topuphistory:edit')")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Topuphistory topuphistory)
    {
        return toAjax(topuphistoryService.updateTopuphistory(topuphistory));
    }

    /**
     * 删除充值记录
     */
    @PreAuthorize("@ss.hasPermi('topuphistory:topuphistory:remove')")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topuphistoryIds}")
    public AjaxResult remove(@PathVariable Long[] topuphistoryIds)
    {
        return toAjax(topuphistoryService.deleteTopuphistoryByTopuphistoryIds(topuphistoryIds));
    }
}
